<?php
header("content-type:text/html;charset=utf-8");//调整页面编码格式
try {
    $dbh = new PDO('mysql:host=127.0.0.1;dbname=1704phpA','root','');//建立与数据库的连接并选择数据库
} catch (Exception $e) {
    die("Unable to connect: " . $e->getMessage());
}

try {
    $dbh->beginTransaction();
    $res=$dbh->exec('update  user  set  money=money-1000 where  user_id=20');
    $res1=$dbh->exec("update  user  set  money=money+1000 where  user_id=21");
    if($res1 &&  $res){
        $dbh->commit();
        echo  "执行成功";
    }else{
        $dbh->rollBack();
    }



} catch (Exception $e) {
    $dbh->rollBack();
    echo "Failed: " . $e->getMessage();
}